#ifndef __CHIP_SPI_HPP__
#define __CHIP_SPI_HPP__

#include <iostream>
#include <string>

extern "C"
{
#include <rtthread.h>
#include <rtdevice.h>
#include <stdint.h>
#include <drv_spi.h>
#include <stm32f4xx.h>
}

typedef enum
{
    chip_spi_status_fail,
    chip_spi_status_ok,
} chip_spi_status;

class CHIP_SPI
{
private:
    std::string spi_name;
    std::string dev_name;
    struct rt_spi_device *spi_device;

    uint8_t data_width; //etc 8
    uint32_t max_hz;  // etc 40*1000*1000 40Mhz
    uint8_t mode;  //etc [RT_SPI_MASTER | RT_SPI_MODE_3 | RT_SPI_MSB] to use defualt

    chip_spi_status init_flag;
    uint8_t debug_flag; //0 close 1 open
public:
    CHIP_SPI(std::string spi_name,
             std::string dev_name,
             uint16_t cs_pin,  //etc GPIO_PIN_2
             GPIO_TypeDef * cs_port, //etc GPIOA
             uint8_t data_width,
             uint32_t max_hz,
             uint8_t mode);
    ~CHIP_SPI();
    void CHIP_SPI_open_debug();
    void CHIP_SPI_close_debug();
    chip_spi_status CHIP_SPI_read_status();

    void CHIP_SPI_send_uint8(uint8_t send_data);
    void CHIP_SPI_send_uint8_array(uint8_t* send_buff, size_t buff_size);
    void CHIP_SPI_send_uint8_and_read_uint8(uint8_t send_buff, uint8_t *read_buff);
    void CHIP_SPI_send_uint8_array_and_read_uint8_array(const void *send_buf,
                                                        size_t send_length,
                                                        void *recv_buf,
                                                        size_t recv_length);
    void CHIP_SPI_send_uint16(uint16_t send_data);
    void CHIP_SPI_send_uint16_array(uint16_t* send_buff, size_t buff_size);

};

#endif /*__CHIP_SPI_HPP__*/

